﻿using HCore;

namespace MEat
{
    public class Pendulum : MoveEntity
    {
        public Fix r = 5;
        public Fix angle = FixMath.PI / 4;
        private Fix _angleV;

        public Pendulum(int eType, HGame game) : base(eType, game)
        {
        }

        public override void Update(Fix deltaTime)
        {
            Fix gravity = 20;
            Fix a = -gravity * FixMath.Sin(angle) / r;
            _angleV += a * deltaTime;
            angle += _angleV * deltaTime;
            position = new Vector3(r * FixMath.Sin(angle), -r * FixMath.Cos(angle) + r, 0);

            base.Update(deltaTime);
        }

        public override void Dispose()
        {
        }

        public override int CalculateChecksum()
        {
            return position.x.Raw ^ position.y.Raw ^ position.z.Raw;
        }
    }
}